<!--历史数据-->
<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="开始时间:">
              <a-date-picker v-model:value="where.searchBeginTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="结束时间:">
              <a-date-picker v-model:value="where.searchEndTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>

          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="vadId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          :scroll="{ x: 'max-content' }"
        >

          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>

  </div>
</template>

<script>
import { message } from 'ant-design-vue';
import {VehicleAlarmDataApi} from "@/api/property/vechile/VehicleAlarmDataApi";


export default {
  name: 'VehicleManagerRunningstateManagerStateAlarmData',
  components: {
  },
  props: {
    data: Object
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '时间',
          dataIndex: 'sendtime'
        },
        {
          title: '告警类型',
          dataIndex: 'alarmType',
          customRender: function (row) {
            console.log(row);
            if (row.text == 'speed') {
              return '速度异常';
            } else if (row.text == 'harsh_behavior') {
              if (row.record.state == 0) {
                return "急刹车";
              } else if (row.record.state == 1) {
                return "超速行为";
              } else if (row.record.state == 2) {
                return "急转弯";
              } else if (row.record.state == 3) {
                return "急刹和急转弯";
              } else if (row.record.state == 4) {
                return "超速和急转弯";
              } else {
                return '其他的不良行为产生';
              }
            } else if (row.text == 'tow_alarm') {
              return '牵引器告警';
            } else if (row.text == 'sos') {
              return '急救信号';
            } else if (row.text == 'watch_dog') {
              return '开门狗重启';
            } else if (row.text == 'ignition') {
              if (row.record.state == 1) {
                return '点火装置告警-熄火'
              } else if (row.record.state == 0) {
                return '点火装置告警-点火'
              } else {
                return '点火装置告警';
              }
            } else {
              return '-';
            }
          }
        },
        {
          title: '速度km/h',
          dataIndex: 'speed',
          customRender: function (row) {
            return row.text != null ? row.text : '-';
          }
        },
        {
          title: '操作',
          key: 'action',
          width: 280,
          align: 'center'
        }
      ],
      // 表格搜索条件
      where: {"vehicleId" : this.data.vehicleId, orderBy : "sendtime", sortBy : "desc"},
      // 当前编辑数据
      current: null,
    }
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    reload() {
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    reset() {
      this.where.vehicleId = this.data.vehicleId;
      this.where.orderBy = "sendtime";
      this.where.sortBy = "desc";
      this.where.searchBeginTime = '';
      this.where.searchEndTime = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    async remove(row) {
      const result = await VehicleAlarmDataApi.delete({ vadId: row.vadId });
      message.success(result.message);
      this.reload();
    },
    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return VehicleAlarmDataApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>
